#include "serialization.h"
#include <sstream>
#include <iostream>

using namespace std;


std::string Serialize(std::string s)
{
    stringstream ss;
    ss << ' ';
    ss << s.size();
    ss << ' ';
    ss << s;
    ss << ' ';
    return ss.str();
}

std::string Unserialize(std::string s)
{
    istringstream iss(s);
    return  Unserialize(iss);
}
std::string Unserialize(std::istringstream & iss)
{
    int size;
    iss >> size;
    iss.get(); // space;
    string str(size, 0);
    for(int i = 0; i <  size; ++i)
    {
        str[i] = iss.get();
    }
    return str;
}

std::string Unserialize(std::stringstream & iss)
{
    int size;
    iss >> size;
    iss.get(); // space;
    string str(size, 0);
    for(int i = 0; i <  size; ++i)
    {
        str[i] = iss.get();
    }
    return str;
}
